/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import javax.validation.Valid;

import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.service.EstateElevatorSafeUserService;
import org.springblade.modules.admin.service.IEstateElevatorUserService;
import org.springblade.modules.admin.vo.EstateSelectUserVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.admin.entity.EstateElevator;
import org.springblade.modules.admin.vo.EstateElevatorVO;
import org.springblade.modules.admin.wrapper.EstateElevatorWrapper;
import org.springblade.modules.admin.service.IEstateElevatorService;
import org.springblade.core.boot.ctrl.BladeController;

import java.util.List;
import java.util.Map;

/**
 * 物业电梯表 控制器
 *
 * @author ysq
 * @since 2022-05-27
 */
@RestController
@AllArgsConstructor
@RequestMapping("admin/estate/elevator")
@Api(value = "物业电梯表", tags = "物业电梯表接口")
public class EstateElevatorController extends BladeController {

	private final IEstateElevatorService estateElevatorService;
	private final IEstateElevatorUserService estateElevatorUserService;
	private final EstateElevatorSafeUserService estateElevatorSafeUserService;


	/**
	 * 自定义分页 物业电梯表
	 */
	@PostMapping("/page")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "分页", notes = "传入estateElevator")
	public R<IPage<EstateElevatorVO>> page(@RequestBody EstateElevatorVO estateElevator, @RequestBody Query query) {
		IPage<EstateElevatorVO> pages = estateElevatorService.selectEstateElevatorPage(Condition.getPage(query), estateElevator);
		return R.data(pages);
	}

	@GetMapping("/select/address")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "电梯梯号下拉选择数据")
	public R<List<Map<String, Object>>> selectAddress(@ApiParam(value = "物业项目id", required = true) @RequestParam Long estateBuildingId) {
		return R.data(estateElevatorService.selectAddress(estateBuildingId));
	}

	@GetMapping("/select/user")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "电梯管理人下拉选择数据")
	public R<List<Map<String, Object>>> selectUser(@ApiParam(value = "物业项目id", required = true) @RequestParam Long estateBuildingId) {
		return R.data(estateElevatorService.selectUser(estateBuildingId));
	}

	@GetMapping("/select/safe/user")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "电梯安全员下拉选择数据")
	public R<List<Map<String, Object>>> selectSafeUser(@ApiParam(value = "物业项目id", required = true) @RequestParam Long estateBuildingId) {
		return R.data(estateElevatorService.selectSafeUser(estateBuildingId));
	}

	@PostMapping("/distribution")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "电梯分配人员")
	public R distribution(@Valid @RequestBody EstateSelectUserVO selectUserVO) {
		return R.status(estateElevatorUserService.distribution(selectUserVO));
	}

	@PostMapping("/safe")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "电梯安全员")
	public R safe(@Valid @RequestBody EstateSelectUserVO selectUserVO) {
		return R.status(estateElevatorSafeUserService.safe(selectUserVO));
	}


}
